package com.ruoyi.firemen.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.firemen.domain.FmTheoryExamScores;
import com.ruoyi.firemen.mapper.FmTEInfoMapper;
import com.ruoyi.firemen.domain.FmTEInfo;
import com.ruoyi.firemen.service.IFmTEInfoService;

/**
 * 业务理论考核Service业务层处理
 * 
 * @author zmc
 * @date 2024-09-24
 */
@Service
public class FmTEInfoServiceImpl implements IFmTEInfoService 
{
    @Autowired
    private FmTEInfoMapper fmTEInfoMapper;

    /**
     * 查询业务理论考核
     * 
     * @param id 业务理论考核主键
     * @return 业务理论考核
     */
    @Override
    public FmTEInfo selectFmTEInfoById(Long id)
    {
        return fmTEInfoMapper.selectFmTEInfoById(id);
    }

    /**
     * 查询业务理论考核列表
     * 
     * @param fmTEInfo 业务理论考核
     * @return 业务理论考核
     */
    @Override
    public List<FmTEInfo> selectFmTEInfoList(FmTEInfo fmTEInfo)
    {
        return fmTEInfoMapper.selectFmTEInfoList(fmTEInfo);
    }

    /**
     * 新增业务理论考核
     * 
     * @param fmTEInfo 业务理论考核
     * @return 结果
     */
    @Transactional
    @Override
    public int insertFmTEInfo(FmTEInfo fmTEInfo)
    {
        int rows = fmTEInfoMapper.insertFmTEInfo(fmTEInfo);
        insertFmTheoryExamScores(fmTEInfo);
        return rows;
    }

    /**
     * 修改业务理论考核
     * 
     * @param fmTEInfo 业务理论考核
     * @return 结果
     */
    @Transactional
    @Override
    public int updateFmTEInfo(FmTEInfo fmTEInfo)
    {
        fmTEInfoMapper.deleteFmTheoryExamScoresByFirefighterId(fmTEInfo.getId());
        insertFmTheoryExamScores(fmTEInfo);
        return fmTEInfoMapper.updateFmTEInfo(fmTEInfo);
    }

    /**
     * 批量删除业务理论考核
     * 
     * @param ids 需要删除的业务理论考核主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteFmTEInfoByIds(Long[] ids)
    {
        fmTEInfoMapper.deleteFmTheoryExamScoresByFirefighterIds(ids);
        return fmTEInfoMapper.deleteFmTEInfoByIds(ids);
    }

    /**
     * 删除业务理论考核信息
     * 
     * @param id 业务理论考核主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteFmTEInfoById(Long id)
    {
        fmTEInfoMapper.deleteFmTheoryExamScoresByFirefighterId(id);
        return fmTEInfoMapper.deleteFmTEInfoById(id);
    }

    /**
     * 新增业务理论考试成绩信息
     * 
     * @param fmTEInfo 业务理论考核对象
     */
    public void insertFmTheoryExamScores(FmTEInfo fmTEInfo)
    {
        List<FmTheoryExamScores> fmTheoryExamScoresList = fmTEInfo.getFmTheoryExamScoresList();
        Long id = fmTEInfo.getId();
        if (StringUtils.isNotNull(fmTheoryExamScoresList))
        {
            List<FmTheoryExamScores> list = new ArrayList<FmTheoryExamScores>();
            for (FmTheoryExamScores fmTheoryExamScores : fmTheoryExamScoresList)
            {
                fmTheoryExamScores.setFirefighterId(id);
                list.add(fmTheoryExamScores);
            }
            if (list.size() > 0)
            {
                fmTEInfoMapper.batchFmTheoryExamScores(list);
            }
        }
    }
}
